home *** CD-ROM | disk | FTP | other *** search
/ QRZ! Ham Radio 8 / QRZ Ham Radio Callsign Database - Volume 8.iso / mac / unix / next / nextmmap.c < prev    next >
C/C++ Source or Header  |  1996-06-25  |  1KB  |  40 lines

  1. /*    This file contains mmap() and munmap() routines that (sorta) work
  2.     on the NeXT.                            */
  3.  
  4.  
  5. #include <sys/types.h>
  6. #include <sys/mman.h>
  7. #include <mach/mach.h>
  8. #include <fcntl.h>
  9. #include <stdio.h>
  10.  
  11.  
  12. /*    mmap() replacement for NeXTStep.  NeXTStep has mmap(), but it
  13.     requires that virtual memory be allocated before it is called.
  14.     I use a #define in cb.h to redefine mmap() in the normal QRZ!
  15.     routines to use next_mmap().  Also see nsort.c.  Even with this
  16.     fix, nsort doesn't work properly on the NeXT w/o some additional
  17.     help :-(.  BEC (AC4XO)                        */
  18.  
  19. caddr_t next_mmap(caddr_t addr,size_t len,int prot, int flags, int filedes,
  20.          off_t off)
  21. {
  22.   caddr_t mi;
  23.   if(vm_allocate(task_self(),(vm_address_t *) &mi,len,TRUE)!=KERN_SUCCESS)
  24.     return NULL;
  25.   if(mmap(mi,len,prot,flags,filedes,off)==-1) return NULL;
  26.   return mi;
  27. }
  28.  
  29.  
  30. /*    munmap() replacement for NeXTStep.  Just deallocate the virtual
  31.     memory.                                */
  32.  
  33. void munmap(void *addr,int size)
  34. {
  35.   if(vm_deallocate(task_self(),(vm_address_t) addr,size)!=KERN_SUCCESS) {
  36.     perror("vm_deallocate");
  37.     exit(1);
  38.   }
  39. }
  40.